import Reflux from "reflux"
import GUtils from "@/utils";
import {Link} from "react-router-dom";
import React from "react";

const prefix = "/system/super/";
const api = {
    initShopGeo:prefix+"initShopGeo",
    queryWxPayInfo:prefix+"queryWxPayInfo",
    queryWxRefundInfo:prefix+"queryWxRefundInfo",


    testDevice:prefix+"testDevice",
    bindDevice:prefix+"bindDevice",

    jparkingAccountList:prefix+"jparking/accountList",
    jparkingDiscount:prefix+"jparking/doDiscount",
    jparkingSearch:prefix+"jparking/search"
};

const createAction = () => {
    const Action = Reflux.createActions({
        unmount:{},
        initShopGeo:{asyncResult:true},
        queryWxPayInfo:{asyncResult:true},
        queryWxRefundInfo:{asyncResult:true},
        testDevice:{asyncResult:true},
        bindDevice:{asyncResult:true},

        jparkingAccountList:{asyncResult:true},
        jparkingDiscount:{asyncResult:true},
        jparkingSearch:{asyncResult:true}
    });
    Action.initShopGeo.listen(function () {
        GUtils.jsonAjax.post(api.initShopGeo, {}).then(this.completed, this.failed)
    })
    Action.queryWxPayInfo.listen(function (orderNo) {
        GUtils.Ajax.post(api.queryWxPayInfo, {orderNo}).then(this.completed, this.failed)
    })

    Action.queryWxRefundInfo.listen(function (orderNo) {
        GUtils.Ajax.post(api.queryWxRefundInfo, {orderNo}).then(this.completed, this.failed)
    })

    Action.testDevice.listen(function (subAddress, pubAddress) {
        GUtils.Ajax.post(api.testDevice, {subAddress, pubAddress}).then(this.completed, this.failed)
    })

    Action.bindDevice.listen(function (subAddress, pubAddress,deviceId) {
        GUtils.Ajax.post(api.bindDevice, {subAddress, pubAddress,deviceId}).then(this.completed, this.failed)
    })

    Action.jparkingAccountList.listen(function () {
        GUtils.Ajax.get(api.jparkingAccountList, {}).then(this.completed, this.failed)
    })
    Action.jparkingDiscount.listen(function (accountId, carNo) {
        GUtils.Ajax.post(api.jparkingDiscount, {accountId, carNo}).then(this.completed, this.failed)
    })
    Action.jparkingSearch.listen(function (accountId, so) {
        GUtils.jsonAjax.post(api.jparkingSearch+"?accountId="+accountId, so).then(this.completed, this.failed)
    })
    return Action;
};

const jparkingColumns = [
    {title: "优惠记录编号", dataIndex: "discountCode", width: 190},
    {title: "优惠车牌", dataIndex: "carNo", width: 120},
    {title: "关联订单", dataIndex: "carNo", width: 180,render:(v,vo)=>{
        vo = vo.washOrder;
        if(!vo) return null;

        return <div>
            <div>单号： <Link to={`${window.CONFIG.PAGE_WASH_ORDER}/detail/view?id=${vo.id}`}>{vo.orderNo}</Link></div>
        </div>
    }},
    {title: "发放备注", dataIndex: "remark", width: 120},
    {title: "优惠状态", dataIndex: "favourStatusStr", width: 120},
    {title: "进场时间", dataIndex: "carInTime", width: 180},
    {title: "出场时间", dataIndex: "carOutTime", width: 180},
    {title: "优惠使用时间", dataIndex: "planUseTime", width: 180},
]

export {api, createAction, jparkingColumns}